package com.zyd.shiro.persistence.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.zyd.shiro.persistence.beans.TrainUser;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface MallTrainUserDao extends JpaRepository<TrainUser,Integer>,JpaSpecificationExecutor<TrainUser>{

    @Query(value = "select * from mall_train_user ",nativeQuery = true)
    List<TrainUser> findAllM();

    @Query(value = "select count(*) from mall_train_user bean where bean.train_id = ?1 and bean.ispay = '1'",nativeQuery = true)
    int countAllByTrain_idEquals(Integer trainId);

    @Query(value = "select count(*) from mall_train_user bean where bean.train_id = ?1 and bean.ispay = '0'",nativeQuery = true)
    int countAllByTrain_idEqualsAndNoPay(Integer trainId);

    @Query(value = "select * from mall_train_user bean where bean.train_id = ?1",nativeQuery = true)
    List<TrainUser> getAllByTrain_idEquals(Integer trainId);


    @Query(value = "select * from mall_train_user bean where bean.train_id = ?1 and bean.ispay = ?2",nativeQuery = true)
    List<TrainUser> getAllByTrain_idEquals(Integer trainId,int type);

    @Query(value = "select * from mall_train_user bean where bean.user_id = ?1",nativeQuery = true)
    List<TrainUser> getAllByUser_idEquals(Integer userID);


    @Query(value = "select * from mall_train_user bean where bean.train_id = ?1 and bean.user_id = ?2",nativeQuery = true)
    List<TrainUser> getAllByTrain_idEqualsandUAndUser_idEquals(Integer trainId,Integer userId);

    @Query(value = "select count(*) from mall_train_user bean where bean.train_id = ?1 and bean.user_id = ?2",nativeQuery = true)
    int isJoinTheTrain(Integer trainId,Integer userId);

}
